package com.isomentricengine.core
{
	import com.isomentricengine.character.BaseCharacter;
	import com.isomentricengine.map.IMap;
	import com.isomentricengine.tile.BaseTile;
	import com.isomentricengine.vo.CornersData;
	import com.medusa.core.extension.StaticExtension;

	public class CoordinateUtil extends StaticExtension
	{
		public function CoordinateUtil()
		{
			super();
		}
		
		public static function getCorners(character:BaseCharacter, currentMap:IMap, gameEngine:GameEngine, x:Number, y:Number):CornersData
		{
			var cornersObject:CornersData = new CornersData();
			
			cornersObject.downY = Math.floor((y + (character.height * 0.5) - 1) / currentMap.tileH);
			cornersObject.upY = Math.floor((y - (character.height * 0.5)) / currentMap.tileH);
			cornersObject.leftX = Math.floor((x - (character.width * 0.5)) / currentMap.tileW);
			cornersObject.rightX = Math.floor((x + (character.width * 0.5) - 1) / currentMap.tileW);
			
			cornersObject.upleft = BaseTile(gameEngine.getChildByName("tile_" + cornersObject.upY + "_" + cornersObject.leftX)).walkable;
  			cornersObject.downleft = BaseTile(gameEngine.getChildByName("tile_" + cornersObject.downY + "_" + cornersObject.leftX)).walkable;
  			cornersObject.upright = BaseTile(gameEngine.getChildByName("tile_" + cornersObject.upY+"_" + cornersObject.rightX)).walkable;
  			cornersObject.downright = BaseTile(gameEngine.getChildByName("tile_" + cornersObject.downY + "_" + cornersObject.rightX)).walkable;
			
			return cornersObject;
		}
		
	}
}